//package com.kocla.mz.circularanimutil;
//
//import android.animation.Animator;
//import android.animation.AnimatorSet;
//import android.animation.ArgbEvaluator;
//import android.animation.ObjectAnimator;
//import android.os.Build;
//import android.os.Bundle;
//import android.support.annotation.RequiresApi;
//import android.support.v7.app.AppCompatActivity;
//import android.view.View;
//import android.view.ViewAnimationUtils;
//import android.view.ViewGroup;
//import android.view.animation.AccelerateDecelerateInterpolator;
//import android.widget.TextView;
//
//
//public class SecondActivity_bak extends AppCompatActivity {
//
//    private View content;
//    private TextView text1;
//    private int mX;
//    private int mY;
//    private int mFromColor;
//    private int defaultColor;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_second);
//        //content = findViewById(R.id.reveal_content);
//        content = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
//        text1 = (TextView) findViewById(android.R.id.text1);
//        defaultColor = getResources().getColor(R.color.violet_dark);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            content.post(new Runnable() {
//                @Override
//                public void run() {
//                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//                        mX = getIntent().getIntExtra("x", 0);
//                        mY = getIntent().getIntExtra("y", 0);
//                        mFromColor = getIntent().getIntExtra("fromColor", defaultColor);
//                        Animator animator;
//                        if (mFromColor != defaultColor) {
//                            animator = createRevealAnimatorSet(false, mX, mY, false);
//                        } else {
//                            animator = createRevealAnimator(false, mX, mY);
//                        }
//                        animator.start();
//                    }
//                }
//            });
//
////        content.setOnTouchListener(new View.OnTouchListener() {
////            @Override
////            public boolean onTouch(View v, MotionEvent event) {
////                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
////                    Animator animator = createRevealAnimator(true, (int) event.getX(), (int) event.getY());
////                    animator.start();
////                } else {
////                    finish();
////                }
////                return false;
////            }
////        });
//        }
//
//    }
//
//
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    private Animator createRevealAnimator(boolean reversed, int x, int y) {
//        float hypot = (float) Math.hypot(content.getHeight(), content.getWidth());
//        float startRadius = reversed ? hypot : 0;
//        float endRadius = reversed ? 0 : hypot;
//
//        Animator animator = ViewAnimationUtils.createCircularReveal(
//                content, x, y,
//                startRadius,
//                endRadius);
//        animator.setDuration(800);
//        animator.setInterpolator(new AccelerateDecelerateInterpolator());
//        if (reversed)
//            animator.addListener(animatorListener);
//        return animator;
//    }
//
//    /**
//     * @param reversed      进入动画
//     * @param x-
//     * @param y-
//     * @param colorReversed false 颜色进入动画,
//     *                      true 颜色退出动画
//     * @return
//     */
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    private AnimatorSet createRevealAnimatorSet(boolean reversed, int x, int y, boolean colorReversed) {
//        float hypot = (float) Math.hypot(content.getHeight(), content.getWidth());
//        float startRadius = reversed ? hypot : 0;
//        float endRadius = reversed ? 0 : hypot;
//
//        AnimatorSet animatorSet = new AnimatorSet();
//        Animator animator = ViewAnimationUtils.createCircularReveal(
//                content, x, y,
//                startRadius,
//                endRadius);
//        animator.setDuration(800);
//        animator.setInterpolator(new AccelerateDecelerateInterpolator());
//        if (reversed)
//            animator.addListener(animatorListener);
//        //
//        ObjectAnimator backgroundColorAnimator;
//        if (!colorReversed) {
//            backgroundColorAnimator = ObjectAnimator.ofInt(text1, "backgroundColor", mFromColor, defaultColor);
//        } else {
//            backgroundColorAnimator = ObjectAnimator.ofInt(text1, "backgroundColor", defaultColor, mFromColor);
//        }
//        backgroundColorAnimator.setDuration(800);
//        backgroundColorAnimator.setEvaluator(new ArgbEvaluator());
//        backgroundColorAnimator.start();
//        //
//        animatorSet.playTogether(animator, backgroundColorAnimator);
//        return animatorSet;
//    }
//
//    private Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() {
//        @Override
//        public void onAnimationStart(Animator animation) {
//        }
//
//        @Override
//        public void onAnimationEnd(Animator animation) {
//            content.setVisibility(View.INVISIBLE);
//            finish();
//        }
//
//        @Override
//        public void onAnimationCancel(Animator animation) {
//        }
//
//        @Override
//        public void onAnimationRepeat(Animator animation) {
//        }
//    };
//
//    @Override
//    public void onBackPressed() {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            //Animator animator = createRevealAnimator(true, mX, mY);
//            Animator animator;
//            if (mFromColor != defaultColor) {
//                animator = createRevealAnimatorSet(true, mX, mY, true);
//            } else {
//                animator = createRevealAnimator(true, mX, mY);
//            }
//            animator.start();
//        } else {
//            finish();
//        }
//    }
//}
